{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CSV\n",
    "A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas.\n",
    "\n",
    "逗号分隔值 （CSV） 文件是使用逗号分隔值的分隔文本文件。文件的每一行都是一条数据记录。每条记录由一个或多个字段组成，用逗号分隔。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Document(page_content='Team: Nationals\\nPayroll (millions): 81.34\\nWins: 98', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 0}),\n",
       " Document(page_content='Team: Reds\\nPayroll (millions): 82.20\\nWins: 97', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 1}),\n",
       " Document(page_content='Team: Yankees\\nPayroll (millions): 197.96\\nWins: 95', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 2})]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_community.document_loaders.csv_loader import CSVLoader\n",
    "\n",
    "\n",
    "loader = CSVLoader(file_path='../data/mlb_teams_2012.csv')\n",
    "loader.load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Document(page_content='MLB Team: Team\\nPayroll in millions: Payroll (millions)\\nWins: Wins', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 0}),\n",
       " Document(page_content='MLB Team: Nationals\\nPayroll in millions: 81.34\\nWins: 98', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 1}),\n",
       " Document(page_content='MLB Team: Reds\\nPayroll in millions: 82.20\\nWins: 97', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 2}),\n",
       " Document(page_content='MLB Team: Yankees\\nPayroll in millions: 197.96\\nWins: 95', metadata={'source': '../data/mlb_teams_2012.csv', 'row': 3})]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loader = CSVLoader(file_path='../data/mlb_teams_2012.csv', csv_args={\n",
    "    'delimiter': ',',\n",
    "    'quotechar': '\"',\n",
    "    'fieldnames': ['MLB Team', 'Payroll in millions', 'Wins']\n",
    "})\n",
    "\n",
    "loader.load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Document(page_content='Team: Nationals\\nPayroll (millions): 81.34\\nWins: 98', metadata={'source': '98', 'row': 0}),\n",
       " Document(page_content='Team: Reds\\nPayroll (millions): 82.20\\nWins: 97', metadata={'source': '97', 'row': 1}),\n",
       " Document(page_content='Team: Yankees\\nPayroll (millions): 197.96\\nWins: 95', metadata={'source': '95', 'row': 2})]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loader = CSVLoader(file_path='../data/mlb_teams_2012.csv', source_column=\"Wins\")\n",
    "\n",
    "loader.load()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "langchain0_1",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
